/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.guilayer.match.components;

import it.unical.canonaco.rende.igpe.game.cbv.guilayer.components.OverallGUILayoutFactory;
import it.unical.canonaco.rende.igpe.game.cbv.guilayer.sprites.SpriteSheetCache;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Label;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;

import javax.imageio.ImageIO;
import javax.imageio.stream.FileImageInputStream;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;

/**
 * @author Massimo Canonaco
 *
 */
class JLAttackDataRender extends JPanel implements ListCellRenderer {

	/** */
	private Color selected;
	
	/** */
	private Color unSelected;
	
//	/** */
//	private Color textColor;

	/** */
	private JLabel name;
	
	/** */
	private JLabel gold;
	
	/** */
	private JLabel friendly;
	
	/** */
	private JLabel area;
	
	private static String ATTACK_DATA_WIDTH = "characterinformationpanel.attacks.width";
	private static String ATTACK_DATA_HEIGHT = "characterinformationpanel.attacks.height";
	
	/** */
	public JLAttackDataRender(Map<String, String> settings, Color selected, Color unselected, SpriteSheetCache imgCache) 
	{
		
		super();
		this.setPreferredSize(new Dimension(Integer.parseInt(settings.get(ATTACK_DATA_WIDTH)),
											Integer.parseInt(settings.get(ATTACK_DATA_HEIGHT))));
		OverallGUILayoutFactory guiFactory = OverallGUILayoutFactory.getInstance();
		name = new JLabel();
		gold = new JLabel();
//		this.textColor = guiFactory.getParsedColor(settings.get("characterinformationpanel.ability.text.color"));
		try 
		{
			gold.setIcon(new ImageIcon(ImageIO.read(new FileInputStream(settings.get("characterinformationpanel.skillpoint.smallicon.path")))));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		friendly = new JLabel();
		area = new JLabel();
		
//		setOpaque(false);
		
		Font font = guiFactory.getHeaderFont().deriveFont(18.0f);
		name.setOpaque(false);
		name.setFont(font);
		name.setForeground(guiFactory.getParsedColor(settings.get("characterinformationpanel.ability.text.color")));
		friendly.setOpaque(false);
		area.setOpaque(false);
		gold.setOpaque(false);
		
		add(name);
		add(friendly);
		add(area);
		add(gold);
		
		this.selected = selected;
		this.unSelected = unselected;
//		unSelected = Color.orange;
//		setBackground(Color.red);
//		setOpaque(false);
		setOpaque(true);
	}
	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) 
	{
		
		if(isSelected)
		{
//			setBackground(selected);
//			setForeground(sele);
			setBackground(selected);
//			setOpaque(true);
		}
		else
		{
//			setBackground(unSelected);
//			setForeground(list.getForeground());
//			setBackground(list.getBackground());
			setBackground(unSelected);
		}
//		
//		setOpaque(false);
		if(value instanceof JListAttackData)
		{
		
//			int width = (name.getWidth()*2)+gold.getWidth()+friendly.getWidth()+area.getWidth()+gold.getWidth()+7,
//					height = gold.getHeight()+1;
//			setPreferredSize(new Dimension(100, height));
			JListAttackData val = (JListAttackData) value;
			name.setText(val.displayName);
			gold.setText(val.getCost());
			
			friendly.setIcon(val.getFriendlyIcon());
			area.setIcon(val.getAoEIcon());

//			setText(val.displayName);
//			try {
//				setIcon(new ImageIcon(ImageIO.read(new FileInputStream("testFolder"+File.separator+"aoe_on.png"))));
//			} catch (FileNotFoundException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			} catch (IOException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
		}
		return this;
	}

}
